using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;

namespace UKVSTS.SimpleImageEditControl
{
    public partial class SimpleImageEditControl : UserControl
    {

        public Image Image
        {
            get { return simpleImageEditSurface1.Image; }
            set { simpleImageEditSurface1.Image = value; }
        }

        
        public SimpleImageEditControl()
        {
            InitializeComponent();
            cmdZoom.SelectedIndex = 0;
        }

        public Image GetModifiedImage()
        {
            return simpleImageEditSurface1.GetModifiedImage();
        }

        public bool HasImageChanged
        {
            get { return simpleImageEditSurface1.IsDirty; }
        }

        public SimpleImageEditSurface.Mode Mode {
            get { return this.simpleImageEditSurface1.CurrentMode; }
            set
            {
                simpleImageEditSurface1.CurrentMode = value;

                cmdHighlighter.Checked = value == SimpleImageEditSurface.Mode.FreeHandHighlighter;
                cmdCrop.Checked = value == SimpleImageEditSurface.Mode.Cropping;
                cmdMagnify.Checked = value == SimpleImageEditSurface.Mode.Magnify;
                cmdDrawRectangle.Checked = value == SimpleImageEditSurface.Mode.DrawingRectangles;
                cmdHand.Checked = value == SimpleImageEditSurface.Mode.Scrolling;
            }

        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            //cmdHighlighter.Checked = false;
            //cmdCrop.Checked = false;
            //cmdMagnify.Checked = true;
            //cmdDrawRectangle.Checked = false;
            //cmdHand.Checked = false;
            Mode = SimpleImageEditSurface.Mode.Magnify;

        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            //cmdHighlighter.Checked = false;
            //cmdCrop.Checked = true;
            //cmdMagnify.Checked = false;
            //cmdDrawRectangle.Checked = false;
            //cmdHand.Checked = false;
            //simpleImageEditSurface1.CurrentMode = SimpleImageEditSurface.Mode.Cropping;
            Mode = SimpleImageEditSurface.Mode.Cropping;
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            //cmdHighlighter.Checked = true;
            //cmdCrop.Checked = false;
            //cmdMagnify.Checked = false;
            //cmdDrawRectangle.Checked = false;
            //cmdHand.Checked = false;
            //simpleImageEditSurface1.CurrentMode = SimpleImageEditSurface.Mode.FreeHandHighlighter;
            Mode = SimpleImageEditSurface.Mode.FreeHandHighlighter;
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            //cmdHighlighter.Checked = false;
            //cmdCrop.Checked = false;
            //cmdMagnify.Checked = false;
            //cmdDrawRectangle.Checked = false;
            //cmdHand.Checked = true;
            //simpleImageEditSurface1.CurrentMode = SimpleImageEditSurface.Mode.Scrolling;
            Mode = SimpleImageEditSurface.Mode.Scrolling;
        }

        private void toolStripButton7_Click(object sender, EventArgs e)
        {
            //cmdHighlighter.Checked = false;
            //cmdCrop.Checked = false;
            //cmdMagnify.Checked = false;
            //cmdDrawRectangle.Checked = true;
            //cmdHand.Checked = false;
            //simpleImageEditSurface1.CurrentMode = SimpleImageEditSurface.Mode.DrawingRectangles;
            Mode = SimpleImageEditSurface.Mode.DrawingRectangles;
        }

        private void cmdZoom_SelectedIndexChanged(object sender, EventArgs e)
        {
            simpleImageEditSurface1.ZoomFactor = 1 << cmdZoom.SelectedIndex;
        }

        private void simpleImageEditSurface1_ZoomChanged(object sender, int newLevel)
        {
            int currentZoom = 1 << cmdZoom.SelectedIndex;

            if (currentZoom != newLevel)
            {
                for (int i = 0; i < cmdZoom.Items.Count; i++) {
                    if ((newLevel >> i) == 1)
                    {
                        cmdZoom.SelectedIndex = i;
                        break;
                    }
                }
                
            }
        }


    }
}
